﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="App1.GroupedItemsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:data="using:App1.Data"
    xmlns:common="using:App1.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    >

    <Page.Resources>

        <common:LivroInfantilTemplateSelector
            x:Key="TemplatePersonalizado"             
          PaginaLida="{StaticResource TemplatePaginaLida}"
          PaginaNaoLida="{StaticResource PaginaNaoLidaFull}"
          UltimaPaginaLida="{StaticResource TemplatePaginaLida}" 
         >
        </common:LivroInfantilTemplateSelector>
        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Capitulos}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"
            d:Source="{Binding TodosCapitulos, Source={d:DesignInstance Type=data:DataSourceLivro, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>
   
        <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle }"  Background="{StaticResource Fundo}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid used in most view states -->
      

            <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"
            ItemTemplateSelector="{StaticResource TemplatePersonalizado}"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"            
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick"
            Padding="0,150,120,0" Margin="450,0,0,0"
           >
            
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>                    
                    <VirtualizingStackPanel Orientation="Horizontal"  >                        
                    </VirtualizingStackPanel>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,0" Style="{StaticResource CorFundoCabecalhoCapitulo}">
                                <Button 
                                    AutomationProperties.Name="Group Title"
                                    Click="Header_Click"
                                    Style="{StaticResource TextPrimaryButtonStyle}" >
                                    <StackPanel Orientation="Horizontal"  >
                                        <TextBlock Text="{Binding Titulo}" Padding="10,10,20,20" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Padding="10,10,20,20" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>                        
                        <ItemsPanelTemplate >
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,-10,0,0" Height="520"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Grouped Items"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard80ItemTemplate}"
            SelectionMode="None"
            Background="#3CB371"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Click="Header_Click"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Titulo}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <!-- Back button and page title -->
        <Grid  >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            
            <StackPanel Orientation="Horizontal" Margin="120,0,0,0" Height="110" x:Name="PainelTitulo"
                        AutomationProperties.AutomationId="tituloSnapped" AutomationProperties.Name="TituloSnapped"  >
                <Border Padding="10" Style="{StaticResource CorFundoTituloPagina}">
                    <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}"
                                   Style="{StaticResource TextoCabecalhoPagina}" ></TextBlock>
                </Border>
                <Image x:Name="ImgCabecalho" Style="{StaticResource ImagemCabecalhoPagina}" Source="{StaticResource ImagemCabecalho}" >

                </Image>

            </StackPanel>
            
            </Grid>


        <Border Width="350" Margin="-830,-20,0,0" CornerRadius="30" Height="590" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}" Grid.Column="0" Grid.Row="1" >
            
            <StackPanel>
            <TextBlock  FontSize="22" Margin="20" TextWrapping="Wrap" Text="Continue lendo..."/>
       


        <Button  HorizontalAlignment="Left" 
                    AutomationProperties.AutomationId="boxInicio"
                    AutomationProperties.Name="Box inicial"
                    x:Name="BoxInicio"
                     VerticalAlignment="Top"
                     Background="Black"
                    Height="526"  Width="350"
                     BorderThickness="0" BorderBrush="Black" 
                 Margin="0,20,0,0"
                 Click="BoxInicio_Click_1"
                 >
                <ContentControl Margin="-15,-10,-15,16">
                    <StackPanel >
                        <Image Height="520" Source="{StaticResource ImagemBoxInicial}" Stretch="UniformToFill" 
                               Width="352" />
                            

                            <TextBlock FontSize="28" Margin="20,0,20,20" TextWrapping="Wrap" Width="280" Height="170" TextTrimming="WordEllipsis" Text="{Binding Descricao}"/>
        </StackPanel>
    </ContentControl>
        </Button>

         </StackPanel></Border>
        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,137,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="5,0,00,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Height">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="60"/>
                        </ObjectAnimationUsingKeyFrames>


                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Width">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="200"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="15,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BoxInicio" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PainelTitulo" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="40,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImgCabecalho" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="-50,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
